package com.newtouch.bxzs.database.synchronize.batch.step;

import com.newtouch.bxzs.common.base.model.CooperationCompanyOrganization;
import com.newtouch.bxzs.common.base.model.Organization;
import com.newtouch.bxzs.database.synchronize.batch.process.ProcesorOrganization;
import com.newtouch.bxzs.database.synchronize.batch.reader.ReaderData;
import com.newtouch.bxzs.database.synchronize.batch.writer.WriterOrganization;
import com.newtouch.bxzs.database.synchronize.model.OrganizationBO;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 机构同步step
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 10:59</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class OrganizationStep {

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    private ReaderData readerData;

    @Autowired
    private WriterOrganization writerOrganization;

    @Autowired
    private ProcesorOrganization procesorOrganization;

    /**批处理本端银行机构数据*/
    public Step bankOrganStep(){
        return stepBuilderFactory.get("BankOrganStep")
                .<OrganizationBO, Organization>chunk(100)
                .reader(readerData.synchronizeOwnOrganrList())
                .processor(procesorOrganization.processorOwnOrgan() )
                .writer(writerOrganization.addOwnOrganList())
                .faultTolerant()
                .skip(Exception.class)
                .skipLimit(100)
                .build();
    }

    /**批处理同步对端机构数据*/
    public Step insuranceOrganStep(){
        return stepBuilderFactory.get("insuranceOrganStep")
                .<OrganizationBO, CooperationCompanyOrganization>chunk(100)
                .reader(readerData.getOppositeOrganizationOther())
                .processor(procesorOrganization.processorCooperationOrgan())
                .writer(writerOrganization.addOppositeOrganList())
                .faultTolerant()
                .skip(Exception.class)
                .skipLimit(100)
                .build();
    }
}
